/**
 * Created by Administrator on 2017/10/19 0019.
 */

layui.use('form', function() {
    var form = layui.form;
    form.on('select(type)',function (date) {
        //URI 和父级元素的显示和隐藏
        var val = date.value;
        if (val>1){
            $("#utyle").removeClass("layui-hide").find("input").attr("lay-verify","required");
            if(val != 9){
                $("#mstyle").removeClass("layui-hide").find("input").attr("lay-verify","required");
            }else{
                $("#mstyle").addClass("layui-hide").find("input").removeAttr("lay-verify");
            }
        }else{
            $("#mstyle").addClass("layui-hide").removeAttr("lay-verify");
            $("#utyle").addClass("layui-hide").removeAttr("lay-verify");
        }
        if (val==3){
            $("#btnId").removeClass("layui-hide");
        }else{
            $("#btnId").addClass("layui-hide");
        }

        $.ajax({
            url:"/type",
            type:"get",
            data:{type:val==2?1:2},
            datatype:"json",
            success:function (date,msg) {
                $("#module").empty()//删除原有的内容
                $.each(date,function (a,proper) {
                    $("#module").append("<option value='"+proper.id+"'>"+proper.name+"</option>")
                })
                form.render('select'); //刷新select选择框渲染
            },
            error:function () {

            }
        })
    })
})
